/*************************************************************************
> File Name: cite.c
> Author: hzy
> Created Time: 2023-08-08 10:46:09
> Description:  函数形参的引用
************************************************************************/
#include <iostream>

using namespace std;

void swap(int a, int b) //值传参:将实参的值复制给形参变量,形参变量的修改不会改变实参的值
{
    cout << __LINE__ << ", a = " << a << ", b = " << b << endl;
    int tmp = a;
    a = b;
    b = tmp;
    cout << __LINE__ << ", a = " << a << ", b = " << b << endl;
}

//C++中的方式
void Swap(int &a, int &b) //&a和&b 就是分别对x和y取别名，函数内部访问的就是x,y本身
{
    int tmp = a;
    a = b;
    b = tmp;
}
/*C语言中的方式
    void Swap(int *a, int *b)
    {
        int tmp = *a;
        *a = *b;
        *b = tmp;
    }
*/

int main()
{
    int x = 5;
    int y = 3;
    cout << __LINE__ << ", x = " << x << ", y = " << y << endl;
    swap(x, y);
    cout << __LINE__ << ", x = " << x << ", y = " << y << endl;
    Swap(x, y);
    cout << __LINE__ << ", x = " << x << ", y = " << y << endl;

    return 0;
}